//package com.angel.bo.auth.client.config.security.handler;
//
//import com.alibaba.fastjson.JSON;
//import com.angel.bo.admin.config.security.JwtInfo;
//import com.angel.bo.admin.config.security.bean.AuthUser;
//import com.angel.bo.admin.config.security.jwt.DefaultJwtTokenUtil;
//import com.angel.bo.common.msg.WebReturn;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.MediaType;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//
///**
// * @author zhangwei
// * @date 2018/4/26 16:28
// * @desc spring security 登录成功事件监听
// */
//@Component
//public class LoginSuccessEnventHandler extends SavedRequestAwareAuthenticationSuccessHandler {
//
//    @Autowired
//    private DefaultJwtTokenUtil jwtTokenUtil;
//
//    @Override
//    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException {
//        //在这里生成token,用户访问时放在header里,当用户携带token进行请求时,通过自定义的JwtAuthorizationTokenFilter进行鉴权
//        response.setHeader("Content-Type", MediaType.APPLICATION_JSON_UTF8_VALUE);
//        AuthUser user = (AuthUser) authentication.getPrincipal();
//        JwtInfo jwtInfo = new JwtInfo(user);
//        String token = jwtTokenUtil.generateToken(jwtInfo);
//        WebReturn<AuthUser> model = new WebReturn<>(HttpStatus.OK.value() + "", jwtInfo, "login success!");
//        response.setHeader("token", token);
//        response.getWriter().print(JSON.toJSONString(model));
//        response.getWriter().flush();
//
//    }
//
//}
